DWFMAPI
;; $Id: DWFMAPI.m 4 2010-10-24 17:30:25Z jollis $

DESCFILE(FN)
 W !,"FILE HEADER",!,"-----------",!
 W $J("FILE NAME:",30),$J($$FILENAME(FN),30),!
 W $J("STORED IN GLOBAL:",30),$J($$GL(FN),30),!
 W !,"FIELDS IN FILE",!,"--------------",!,!
 S I=""
 S FLDNUM=""
 S HDRSTR=$J("FIELD NAME",30)_$J("FIELD TYPE",30)_$J("STORAGE",30)
 W HDRSTR,!
 F I=0:0 S FLDNUM=$O(^DD(FN,FLDNUM)) Q:FLDNUM=""  D
 .W $J($$FLDLABL(FN,FLDNUM),30),$J($$FLDTYPEH(FN,FLDNUM),30),$J($$FLDSTOR(FN,FLDNUM),30),!
 Q

ALLFILES(TARGET)
 N FNAM,FNUM
 N COUNT S COUNT=""
 F COUNT=0:1 S FNUM=$O(^DIC(FNUM)) Q:FNUM=""  D
 .S TARGET(COUNT,"NAME")=$P(^DIC(FNUM,0),"^",1)
 .S TARGET(COUNT,"DDNUM")=$P(^DIC(FNUM,0),"^",2)
 Q

FILENAME(FILENUM)
 N NNFLD
 S NNFLD=$G(^DIC(FILENUM,0))
 S NAMPIECE=$P(NNFLD,"^",1)
 Q NAMPIECE

MOSTRCNT(FILENUM)
 N NNFLD,MRIEN
 S NNFLD=$G(^DIC(FILENUM,0))
 S MRIEN=$P(NNFLD,"^",3)
 Q MRIEN

TOTLENTR(FILENUM)
 N RECCNT S RECCNT=""
 D FILE^DID(FILENUM,"","ENTRIES","RECCNT","")
 Q RECCNT("ENTRIES")

CHARCODE(FILENUM)
 N NNFLD,CCODE
 S NNFLD=$G(^DIC(FILENUM,0))
 S CCODE=$P(NNFLD,"^",2)
 Q $E(CCODE,2,$L(CCODE))

GL(FILENUM)
 Q $G(^DIC(FILENUM,0,"GL"))

FLDLABL(FILENUM,FLDNUM)
 Q $P($G(^DD(FILENUM,FLDNUM,0)),"^",1)

FLDTYPE(FILENUM,FLDNUM)
 Q $P($G(^DD(FILENUM,FLDNUM,0)),"^",2)

FLDTYPEH(FILENUM,FLDNUM)
 N FT
 S FT=$$FLDTYPE(FILENUM,FLDNUM)
 I FT["BC" Q "BoolCmpt"
 I FT["Cm" Q "MltiCmpt"
 I FT["C" Q "Cmpt"
 I FT["DC" Q "CmptDate"
 I FT["D" Q "DateVal"
 I FT["F" Q "FreeTxt"
 I FT["K" Q "MUMPS"
 I FT["N" Q "Number"
 I FT["S" Q "CodeSet"
 I FT["V" Q "VarPtr"
 I FT["WL" Q "WrdPrcL"
 I FT["W" Q "WrdPrc"
 Q "-"

NULLOK(FILENUM,FLDNUM)
 N FT
 S FT=$$FLDTYPE(FILENUM,FLDNUM)
 I FT["R" Q "NO"
 Q "YES"

PRLEN(FILENUM,FLDNUM)
 Q "TODO"

LAYGOPTR(FILENUM,FLDNUM)
 Q "TODO"
 
HASTRNSF(FILENUM,FLDNUM)
 N FT
 S FT=$$FLDTYPE(FILENUM,FLDNUM)
 I FT["O" Q "YES"
 Q "NO"

HASSCRN(FILENUM,FLDNUM)
 N FT
 S FT=$$FLDTYPE(FILENUM,FLDNUM)
 I FT["*" Q "YES"
 Q "NO"

FLDSTOR(FILENUM,FLDNUM)
 Q $P($G(^DD(FILENUM,FLDNUM,0)),"^",4)

FLDSBSCR(FILENUM,FLDNUM)
 Q $P($$FLDSTOR(FILENUM,FLDNUM),";",1)

FLDPIECE(FILENUM,FLDNUM)
 Q $P($$FLDSTOR(FILENUM,FLDNUM),";",2)

FLDVAL(FILENUM,FLDNUM,IEN)
 N GLB S GLB=$$GL^DWFMAPI(FILENUM)
 N SUB S SUB=$$FLDSBSCR^DWFMAPI(FILENUM,FLDNUM)
 N PCE S PCE=$$FLDPIECE^DWFMAPI(FILENUM,FLDNUM)
 N GLR S GLR=GLB_IEN_","""_SUB_""")"
 ;;D trace^%zewdAPI(">>>>>>>>GLR="_GLR)
 N VAL
 I (SUB="")!(PCE="")!(IEN="")!(SUB=" ") Q ""
 I $G(@GLR)="" Q ""
 S VAL=$P($G(@GLR),"^",PCE)
 Q VAL
 
 